package com.tianji.promotion.handler;

import com.tianji.common.constants.MqConstants;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.UserCouponDTO;
import com.tianji.promotion.service.IUserCouponService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Yandel
 * @date 2025/8/19 上午11:13
 * @description:
 */
@Slf4j
@Component
public class PromotionMqHandler {

    @Resource
    private IUserCouponService userCouponService;

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(value = "coupon.receive.queue", durable = "true"),
                    exchange = @Exchange(value = "tj.promotion.exchange", durable = "true", type = ExchangeTypes.TOPIC),
                    key = MqConstants.Key.COUPON_RECEIVE)
    )
    public void onMsg(UserCouponDTO msg) {
        log.info("收到领券消息：{}", msg);
        userCouponService.checkAndCreateCouponNew(msg);


    }


}
